package com.bws.magiccube.log;

import org.apache.log4j.FileAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.Priority;

public class LogWriter {
    private Logger debugLog = null;

    private Logger infoLog = null;

    private Logger warnLog = null;

    private Logger errorLog = null;
    
    public static String ErrMsg = "";

    protected LogWriter(Class classIns) {

//        debugLog = Logger.getLogger(classIns);
//        infoLog = debugLog;
//        warnLog = debugLog;
//        errorLog = debugLog;

        //debugLog = Logger.getLogger("Test.Debug");
        //infoLog = Logger.getLogger("Test.Debug.Info");
        //warnLog = Logger.getLogger("Test.Debug.Info.Warn");
        //errorLog = Logger.getLogger("Test.Debug.Info.Warn.Error");
        debugLog = Logger.getLogger(classIns);
        infoLog = Logger.getLogger(classIns);
        warnLog = Logger.getLogger(classIns);
        errorLog = Logger.getLogger(classIns);
//        String pattern = "%d{ISO8601} - %m %n";
//        PatternLayout layout = new PatternLayout(pattern);
//
//        FileAppender appender = null;
//        try {
//            appender = new FileAppender(layout, "log/debug.log", true);
//        }
//        catch (Exception e) {
//        }
//        debugLog.addAppender(appender);

//        try {
//            appender = new FileAppender(layout, "log/info.log", true);
//        }
//        catch (Exception e) {
//        }
//        infoLog.addAppender(appender);
//        try {
//            appender = new FileAppender(layout, "log/warn.log", true);
//        }
//        catch (Exception e) {
//        }
//        warnLog.addAppender(appender);
//        try {
//            appender = new FileAppender(layout, "log/error.log", true);
//        }
//        catch (Exception e) {
//        }
//        errorLog.addAppender(appender);
    }

    public void Debug(String MessageCode, String[] Args) {
        debugLog.debug(LogHelper.getContent(MessageCode, Args));
    }

    public void Info(String MessageCode, String[] Args) {
        infoLog.info(LogHelper.getContent(MessageCode, Args));
    }

    public void Warn(String MessageCode, String[] Args) {
        warnLog.warn(LogHelper.getContent(MessageCode, Args));
    }

    public void Error(String MessageCode, String[] Args) {
        errorLog.error(LogHelper.getContent(MessageCode, Args));
        ErrMsg += LogHelper.getContent(MessageCode, Args)+"<br>\r\n";
    }

    public void Debug(String Message) {
        debugLog.debug(Message);
    }

    public void Info(String Message) {
        infoLog.info(Message);
    }

    public void Warn(String Message) {
        warnLog.warn(Message);
    }

    public void Error(String Message) {
        errorLog.error(Message);
        ErrMsg+=Message+"<br>\r\n";
    }

    public void Info(String MessageCode, String Param1) {
        // TODO Auto-generated method stub
        String[] args = new String[1];
        args[0] = Param1;
        this.Info(MessageCode, args);
    }

    public void Info(String MessageCode, String Param1, String Param2) {
        // TODO Auto-generated method stub
        String[] args = new String[2];
        args[0] = Param1;
        args[1] = Param2;
        this.Info(MessageCode, args);
    }

    public void Info(String MessageCode, String Param1, String Param2, String Param3) {
        // TODO Auto-generated method stub
        String[] args = new String[3];
        args[0] = Param1;
        args[1] = Param2;
        args[2] = Param3;
        this.Info(MessageCode, args);
    }
    public void Info(String MessageCode, String Param1, String Param2, String Param3,String Param4) {
        // TODO Auto-generated method stub
        String[] args = new String[4];
        args[0] = Param1;
        args[1] = Param2;
        args[2] = Param3;
        args[3] = Param4;
        this.Info(MessageCode, args);
    }
    public void Info(String MessageCode, String Param1, String Param2, String Param3,String Param4,String Param5) {
        // TODO Auto-generated method stub
        String[] args = new String[5];
        args[0] = Param1;
        args[1] = Param2;
        args[2] = Param3;
        args[3] = Param4;
        args[4] = Param5;
        this.Info(MessageCode, args);
    }
    public void Info(String MessageCode, String Param1, String Param2, String Param3,String Param4,String Param5,String Param6) {
        // TODO Auto-generated method stub
        String[] args = new String[6];
        args[0] = Param1;
        args[1] = Param2;
        args[2] = Param3;
        args[3] = Param4;
        args[4] = Param5;
        args[6] = Param6;
        this.Info(MessageCode, args);
    }

    public void Warn(String MessageCode, String Param1) {
        // TODO Auto-generated method stub
        String[] args = new String[1];
        args[0] = Param1;
        this.Warn(MessageCode, args);
    }

    public void Warn(String MessageCode, String Param1, String Param2) {
        // TODO Auto-generated method stub
        String[] args = new String[2];
        args[0] = Param1;
        args[1] = Param2;
        this.Warn(MessageCode, args);
    }

    public void Warn(String MessageCode, String Param1, String Param2, String Param3) {
        // TODO Auto-generated method stub
        String[] args = new String[3];
        args[0] = Param1;
        args[1] = Param2;
        args[2] = Param3;
        this.Warn(MessageCode, args);
    }

    public void Error(String MessageCode, String Param1) {
        // TODO Auto-generated method stub
    	String[] args = new String[1];
        args[0] = Param1;
    	new Exception(LogHelper.getContent(MessageCode, args)).printStackTrace();
        this.Error(MessageCode, args);
    }

    public void Error(String MessageCode, String Param1, String Param2) {
        // TODO Auto-generated method stub
        String[] args = new String[2];
        args[0] = Param1;
        args[1] = Param2;
    	new Exception(LogHelper.getContent(MessageCode, args)).printStackTrace();
        this.Error(MessageCode, args);
    }

    public void Error(String MessageCode, String Param1, String Param2, String Param3) {
        // TODO Auto-generated method stub
        String[] args = new String[3];
        args[0] = Param1;
        args[1] = Param2;
        args[2] = Param3;
    	new Exception(LogHelper.getContent(MessageCode, args)).printStackTrace();
        this.Error(MessageCode, args);
    }
    public void Error(String MessageCode, String Param1, String Param2, String Param3,String Param4) {
        // TODO Auto-generated method stub
        String[] args = new String[4];
        args[0] = Param1;
        args[1] = Param2;
        args[2] = Param3;
        args[3] = Param4;
    	new Exception(LogHelper.getContent(MessageCode, args)).printStackTrace();
        this.Error(MessageCode, args);
    }
    public void Error(String MessageCode, String Param1, String Param2, String Param3,String Param4,String Param5) {
        // TODO Auto-generated method stub
        String[] args = new String[5];
        args[0] = Param1;
        args[1] = Param2;
        args[2] = Param3;
        args[3] = Param4;
        args[4] = Param5;
    	new Exception(LogHelper.getContent(MessageCode, args)).printStackTrace();
        this.Error(MessageCode, args);
    }
    public void Error(String MessageCode, String Param1, String Param2, String Param3,String Param4,String Param5,String Param6) {
        // TODO Auto-generated method stub
        String[] args = new String[6];
        args[0] = Param1;
        args[1] = Param2;
        args[2] = Param3;
        args[3] = Param4;
        args[4] = Param5;
        args[6] = Param6;
    	new Exception(LogHelper.getContent(MessageCode, args)).printStackTrace();
        this.Error(MessageCode, args);
    }
    public void Debug(String MessageCode, String Param1) {
        // TODO Auto-generated method stub
        String[] args = new String[1];
        args[0] = Param1;
        this.Debug(MessageCode, args);
    }

    public void Debug(String MessageCode, String Param1, String Param2) {
        // TODO Auto-generated method stub
        String[] args = new String[2];
        args[0] = Param1;
        args[1] = Param2;
        this.Debug(MessageCode, args);
    }

    public void Debug(String MessageCode, String Param1, String Param2, String Param3) {
        // TODO Auto-generated method stub
        String[] args = new String[3];
        args[0] = Param1;
        args[1] = Param2;
        args[2] = Param3;
        this.Debug(MessageCode, args);
    }
    public void Debug(String MessageCode, String Param1, String Param2, String Param3,String Param4) {
        // TODO Auto-generated method stub
        String[] args = new String[4];
        args[0] = Param1;
        args[1] = Param2;
        args[2] = Param3;
        args[3] = Param4;
        this.Debug(MessageCode, args);
    }
    public void Debug(String MessageCode, String Param1, String Param2, String Param3,String Param4,String Param5) {
        // TODO Auto-generated method stub
        String[] args = new String[5];
        args[0] = Param1;
        args[1] = Param2;
        args[2] = Param3;
        args[3] = Param4;
        args[4] = Param5;
        this.Debug(MessageCode, args);
    }
    public void Debug(String MessageCode, String Param1, String Param2, String Param3,String Param4,String Param5,String Param6) {
        // TODO Auto-generated method stub
        String[] args = new String[6];
        args[0] = Param1;
        args[1] = Param2;
        args[2] = Param3;
        args[3] = Param4;
        args[4] = Param5;
        args[6] = Param6;
        this.Debug(MessageCode, args);
    }
}
